VERSION 5.00
Begin VB.Form frmLogin 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Login"
   ClientHeight    =   2130
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3840
   Icon            =   "frmLogin.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2130
   ScaleWidth      =   3840
   Begin VB.CheckBox chkSavePass 
      Alignment       =   1  'Right Justify
      Caption         =   "Save password"
      Height          =   255
      Left            =   1860
      TabIndex        =   7
      Top             =   1080
      Width           =   1515
   End
   Begin VB.CheckBox Option1 
      Alignment       =   1  'Right Justify
      Caption         =   "Print Test Ticket:"
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   3000
      Width           =   1515
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   375
      Left            =   2280
      TabIndex        =   5
      Top             =   1560
      Width           =   975
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "&OK"
      Height          =   375
      Left            =   1200
      TabIndex        =   4
      Top             =   1560
      Width           =   975
   End
   Begin VB.TextBox txtPass 
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   1200
      PasswordChar    =   "*"
      TabIndex        =   3
      Text            =   "12345"
      Top             =   600
      Width           =   2175
   End
   Begin VB.TextBox txtUserName 
      Height          =   375
      Left            =   1200
      TabIndex        =   2
      Text            =   "admin"
      Top             =   120
      Width           =   2175
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "Password:"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   600
      Width           =   975
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "User name:"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   855
   End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public nFormCall As Integer
Dim fileImportURL As String

Private Sub chkSavePass_Click()
    If chkSavePass.Value = 1 Then
        sPassword = txtPass.Text
    Else
        sPassword = ""
    End If
End Sub

Private Sub cmdCancel_Click()
    CurrentUser = ""
    permit = ""
    isLoged = False
    OKPass = False
    'frmBOMain.Command6.Caption = "&Log In"
    
    Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim sql As String
    Dim rs As New ADODB.Recordset
    
    Dim galileoURL As String
    Dim countfileOfficeExport As Integer
    countfileOfficeExport = 0
    Dim fileOfficeonserver As String
    fileOfficeonserver = ""
    
    If chkSavePass.Value = 1 Then
        sPassword = txtPass.Text
        sUserNameStore = txtUserName.Text
    Else
        sPassword = ""
        sUserNameStore = ""
    End If
   
    sql = "Select * from tbl_pass where username ='" & txtUserName.Text & "' and pass ='" & txtPass.Text & "'"
    
    Call KetNoi
    
    Set rs = adoConnection.Execute(sql)
    
    If Option1.Value = 1 Then
           'Call CheckOut
    Else
    
        If rs.EOF Then
            MsgBox "The username or password you entered is incorrect. Please, try again.", vbCritical, "Accountant Login"
            txtUserName.SetFocus
            CurrentUser = ""
            permit = ""
            isLoged = False
            officeBImport = ""
            Exit Sub
        Else
            CurrentUser = txtUserName.Text
            permit = rs!permit
            Userlogin = rs!Name
            
            isLoged = True
            
            Screen.MousePointer = vbHourglass
            
            MDIForm1.Caption = "Accountant" & " - " & Userlogin
            'change caption for menu mnuUser
            
            galileoURL = "http://www.galileo.com.vn/down/upload/"
            
            If permit = "U" Or permit = "R" Then 'AC
                MDIForm1.xMenu1.MenuTree.item(4).Caption = "Change your password"
                
                fileImportURL = galileoURL & "Approved_data_for_" & stroffice & ".rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = stroffice & " has approved "
                End If
            Else
                If rs!Username = "mac" Then 'AC
                    fileImportURL = galileoURL & "Approved_data_for_" & stroffice & ".rar"
                    If DoesHTTPFileExist(fileImportURL) Then
                        fileOfficeonserver = stroffice & " has approved. - "
                    End If
                End If
            
                MDIForm1.xMenu1.MenuTree.item(4).Caption = "User management"
                If permit = "G" Then
                    officeBImport = ""
                Else
                    officeBImport = "ToMAC"
                End If
                
                fileImportURL = galileoURL & "SGN_" & officeBImport & "exportdata.rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = fileOfficeonserver & "SGN, "
                    countfileOfficeExport = countfileOfficeExport + 1
                End If
                fileImportURL = galileoURL & "HAN_" & officeBImport & "exportdata.rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = fileOfficeonserver & "HAN, "
                    countfileOfficeExport = countfileOfficeExport + 1
                End If
                fileImportURL = galileoURL & "VTE_" & officeBImport & "exportdata.rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = fileOfficeonserver & "VTE, "
                    countfileOfficeExport = countfileOfficeExport + 1
                End If
                fileImportURL = galileoURL & "PNH_" & officeBImport & "exportdata.rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = fileOfficeonserver & "PNH, "
                    countfileOfficeExport = countfileOfficeExport + 1
                End If
                fileImportURL = galileoURL & "IND_" & officeBImport & "exportdata.rar"
                If DoesHTTPFileExist(fileImportURL) Then
                    fileOfficeonserver = fileOfficeonserver & "IND, "
                    countfileOfficeExport = countfileOfficeExport + 1
                End If
                If fileOfficeonserver <> "" Then
                    If countfileOfficeExport > 1 Then
                        fileOfficeonserver = fileOfficeonserver & "are waiting for import"
                    Else
                        fileOfficeonserver = fileOfficeonserver & "is waiting for import"
                    End If
                End If
            End If
            'Call CheckOut
        End If
    End If
    
    'Status kiem tra file co data tren server chua
    If fileOfficeonserver <> "" Then
        MDIForm1.StatusBarMDI.Panels(1).Text = ""
        MDIForm1.StatusBarMDI.Panels(1).Text = fileOfficeonserver
        MDIForm1.StatusBarMDI.Visible = True
    Else
        MDIForm1.StatusBarMDI.Visible = False
    End If
    
    'Call DisconnectDB
    
    RunAtTheFirstTime
    
    If rs.State = adStateOpen Then rs.Close
    
    Set rs = Nothing
    OKPass = True
    'Toolbar login is disable
    MDIForm1.Toolbar1.Buttons(1).Enabled = False
    'xMenu mnulogin is disable
    MDIForm1.xMenu1.MenuTree.item(2).Enabled = False
    
    Call MDIForm1.disableMenuNToolbar(False)
    'frmBOMain.Command6.Caption = "&Log Out"
    'frmBOMain.TrayIcon1.SetMenuLogCaption ("&Log Out")
    Unload Me
    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Load()
    Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
    
    OKPass = False
    txtPass.Text = sPassword
    If sPassword <> "" Then
        chkSavePass.Value = 1
    End If
    txtUserName.Text = sUserNameStore
End Sub
Private Function CheckOut()
'Dim PrintTest As Boolean
'If Option1.Value = 1 Then
'    PrintTest = True
'Else
'    PrintTest = False
'End If
'Select Case nFormCall
'    Case 7
'        If permit = "T" Then
'            MsgBox "You aren't permitted to view reports"
'        Else
'            frmAirLinesRP.Show
'        End If
'    Case 8
'        If permit <> "QT" Then
'            MsgBox "You aren't administrator"
'        Else
'            frmUserManager.Show
'        End If
'End Select

End Function

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    sUserNameStore = txtUserName.Text
End Sub

Private Sub Option1_Click()
    If Option1.Value = 1 Then
        txtUserName.Enabled = False
        txtPass.Enabled = False
    Else
        txtUserName.Enabled = True
        txtPass.Enabled = True
    End If
End Sub

Private Sub txtPass_GotFocus()
    Call SelectText(txtPass)
End Sub

Private Sub txtPass_KeyPress(KeyAscii As Integer)
    If KeyAscii <> 13 Then Exit Sub
    Call cmdOK_Click
    
End Sub

Private Sub txtUserName_GotFocus()
    Call SelectText(txtUserName)
End Sub
